package cn.edu.scau.cmi.chenmiaopeng.controller.factory;

import cn.edu.scau.cmi.chenmiaopeng.factory.commonFactory.*;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;

public class CommonFactoryController {
	@FXML
    private Button confirm;
    @FXML
    private Button confirm_buy;
	@FXML
    private TextArea textarea;
    @FXML
    private ComboBox<String> comboBox;
     @FXML
    private ComboBox<String> comboBox1;
    
    private MeatFactory meatFactory = new MeatFactory();
    private MeatProduction meatProduction;
    private boolean hasCheckMess = false;
    public void clickButton(ActionEvent e) {
    	String option =  comboBox.getValue();
    	if(option.equals("please choose meat:")) {
			textarea.appendText("please choose the meat you want!\n");
		}
    	else {
			meatProduction = meatFactory.getMeatProduction(option);
    		if((Button)e.getSource()==confirm) {
    			    textarea.clear();
        		    System.out.println("选择的是："+option);
        			textarea.appendText(meatProduction.getMeatInfo()+"\n");
//        			if(meatProduction instanceof BeefProduction) {
//        				BeefProduction beef = (BeefProduction)meatProduction;
//            			textarea.appendText(beef.howYummy());
//        			}
        			hasCheckMess = true;
        	}
    		else if((Button)e.getSource()==confirm_buy) {
    			String select = comboBox1.getSelectionModel().getSelectedItem();
    			if(select==null) {
    				return ;
    			}
    			if(select.equals("yes")) {
    				if(hasCheckMess) {
    					textarea.appendText(meatProduction.getMeatProduce()+"\n");
            			comboBox.getSelectionModel().selectFirst();
            			comboBox1.setValue("want to buy?");
            			hasCheckMess = false;
    				}
    				else {
    					textarea.clear();
    					textarea.appendText("You haven't check the information of the meat, are you sure?\n");
    					hasCheckMess = true;
    				}
    			}
    			else {
    				textarea.clear();
    				textarea.appendText("thanks for coming!\n");
    				comboBox.getSelectionModel().selectFirst();
        			comboBox1.setValue("want to buy?");
        			hasCheckMess = false;
    			}
    		}
    	}
    	
    	}
}
